﻿#########################
#### UNITY DECISIONS ####
#########################

# House Head decision - These are only available to the House Head
unity_reinforce_army_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/antagonistic.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_reinforce_army_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}

	is_valid = {
		house = {
			has_house_unity_stage = antagonistic
		}
		is_house_head = yes
	}

	is_valid_showing_failures_only = {
		house = {
			has_house_unity_stage = antagonistic
			NOT = { has_house_unity_modifier = unity_antagonistic_maa_modifier }
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_unity_modifier = {
				modifier = unity_antagonistic_maa_modifier
				years = 10
			}
		}
	}
	
	cost = {
		gold = {
			value = medium_gold_value
		}
		piety = {
			value = unity_major_decision_piety_cost
			add = {
				value = 20
				multiply = {
					value = number_of_landed_house_members_value
					subtract = 1 # We don't want to add any extra for the first ruler
				}
			}
		}
	}
	
	ai_potential = {
		exists = house
		house = { # Don't bother unless you have a few landed house members who would benefit
			any_house_unity_member = {
				count >= 3
			}
		}
		ai_has_warlike_personality = yes
	}

	ai_will_do = {
		base = 25
	}
}

unity_establish_network_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/competitive.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_establish_network_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}

	is_valid = {
		house = {
			has_house_unity_stage = competitive
		}
		is_house_head = yes
	}

	is_valid_showing_failures_only = {
		house = {
			has_house_unity_stage = competitive
			NOT = { has_house_unity_modifier = unity_competitive_spies_modifier }
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_unity_modifier = {
				modifier = unity_competitive_spies_modifier
				years = 10
			}
		}
	}
	
	cost = {
		gold = {
			value = medium_gold_value
		}
		piety = {
			value = unity_major_decision_piety_cost
			add = {
				value = 20
				multiply = {
					value = number_of_landed_house_members_value
					subtract = 1 # We don't want to add any extra for the first ruler
				}
			}
		}
	}
	
	ai_potential = {
		exists = house
		house = { # Don't bother unless you have a few landed house members who would benefit
			any_house_unity_member = {
				count >= 3
			}
		}
		ai_has_cautious_personality = yes
	}

	ai_will_do = {
		base = 25
	}
}

unity_improve_taxation_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/impassive.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_improve_taxation_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}

	is_valid = {
		house = {
			has_house_unity_stage = impassive
		}
		is_house_head = yes
	}

	is_valid_showing_failures_only = {
		house = {
			has_house_unity_stage = impassive
			NOT = { has_house_unity_modifier = unity_impassive_tax_modifier }
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_unity_modifier = {
				modifier = unity_impassive_tax_modifier
				years = 10
			}
		}
	}
	
	cost = {
		piety = {
			value = unity_major_decision_piety_cost
			add = {
				value = 20
				multiply = {
					value = number_of_landed_house_members_value
					subtract = 1 # We don't want to add any extra for the first ruler
				}
			}
		}
	}
	
	ai_potential = {
		exists = house
		house = { # Don't bother unless you have a few landed house members who would benefit
			any_house_unity_member = {
				count >= 3
			}
		}
		ai_has_economical_boom_personality = yes
	}

	ai_will_do = {
		base = 25
	}
}

unity_send_bailiffs_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/friendly.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_send_bailiffs_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}

	is_valid = {
		house = {
			has_house_unity_stage = friendly
		}
		is_house_head = yes
	}

	is_valid_showing_failures_only = {
		house = {
			has_house_unity_stage = friendly
			NOT = { has_house_unity_modifier = unity_friendly_bailiff_modifier }
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_unity_modifier = {
				modifier = unity_friendly_bailiff_modifier
				years = 10
			}
		}
	}
	
	cost = {
		gold = {
			value = medium_gold_value
		}
		piety = {
			value = unity_major_decision_piety_cost
			add = {
				value = 20
				multiply = {
					value = number_of_landed_house_members_value
					subtract = 1 # We don't want to add any extra for the first ruler
				}
			}
		}
	}
	
	ai_potential = {
		exists = house
		house = { # Don't bother unless you have a few landed house members who would benefit
			any_house_unity_member = {
				count >= 3
			}
		}
		OR = {
			ai_has_warlike_personality = yes
			ai_has_economical_boom_personality = yes
		}
	}

	ai_will_do = {
		base = 25
	}
}

unity_placate_vassals_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/harmonious.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_placate_vassals_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}

	is_valid = {
		house = {
			has_house_unity_stage = harmonious
		}
		is_house_head = yes
	}

	is_valid_showing_failures_only = {
		house = {
			has_house_unity_stage = harmonious
			NOT = { has_house_unity_modifier = unity_harmonious_placation_modifier }
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_unity_modifier = {
				modifier = unity_harmonious_placation_modifier
				years = 10
			}
		}
	}
	
	cost = {
		gold = {
			value = medium_gold_value
		}
		piety = {
			value = unity_major_decision_piety_cost
			add = {
				value = 20
				multiply = {
					value = number_of_landed_house_members_value
					subtract = 1 # We don't want to add any extra for the first ruler
				}
			}
		}
	}
	
	ai_potential = {
		exists = house
		house = { # Don't bother unless you have a few landed house members who would benefit
			any_house_unity_member = {
				count >= 3
			}
		}
		ai_has_warlike_personality = no
	}

	ai_will_do = {
		base = 20
	}
}

unity_organize_house_for_war_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_sunder.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_organize_house_for_war_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}
	
	is_valid_showing_failures_only = {
		house = {
			NOT = { has_house_modifier = unity_house_focused_on_economy_modifier } # Cannot promote war while the house is focused on economy already
			OR = {
				has_house_unity_stage = antagonistic
				has_house_unity_stage = competitive
			}
		}
		is_house_head = yes
	}
	
	is_valid = {
		house = {
			OR = {
				has_house_unity_stage = antagonistic
				has_house_unity_stage = competitive
			}
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_modifier = {
				modifier = unity_house_organized_for_war_modifier
				years = 20
			}
		}
	}
	
	cost = {
		piety = {
			value = unity_minor_decision_piety_cost
		}
	}
	
	ai_potential = {
		ai_has_warlike_personality = yes
	}

	ai_will_do = {
		base = 20
	}
}

unity_encourage_house_economy_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3_decision_tax_collector.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_encourage_house_economy_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}
	
	is_valid_showing_failures_only = {
		house = {
			NOT = { has_house_modifier = unity_house_organized_for_war_modifier } # Cannot promote economy while the house is focused on war already
			OR = {
				has_house_unity_stage = friendly
				has_house_unity_stage = harmonious
			}
		}
		is_house_head = yes
	}

	is_valid = {
		house = {
			OR = {
				has_house_unity_stage = friendly
				has_house_unity_stage = harmonious
			}
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_modifier = {
				modifier = unity_house_focused_on_economy_modifier
				years = 20
			}
		}
	}
	
	cost = {
		piety = {
			value = unity_minor_decision_piety_cost
		}
	}
	
	ai_potential = {
		ai_has_economical_boom_personality = yes
	}

	ai_will_do = {
		base = 20
	}
}

unity_steer_house_direction_decision = {
	ai_check_interval = 24
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_foundation.dds"
	}
	#is_invisible = yes
	decision_group_type = house_unity
	
	sort_order = 1500 # We want the decision to be at the top of the list to make it real easy to find.
	
	cooldown = { years = 10 }

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}
	
	is_valid_showing_failures_only = {
		is_house_head = yes
		
		# Option localisation
		trigger_if = {
			limit = { scope:steer_unity_towards_harmonious = yes }
			custom_tooltip = {
				text = steer_unity_towards_harmonious_tt
				NOT = { house = { has_house_unity_stage = harmonious } }
			}
		}
		trigger_if = {
			limit = { scope:steer_unity_towards_antagonistic = yes }
			custom_tooltip = {
				text = steer_unity_towards_antagonistic_tt
				NOT = { house = { has_house_unity_stage = antagonistic } }
			}
		}
	}

	is_valid = {
		is_house_head = yes
	}
	
	widget = {
		gui = "decision_view_widget_unity_steer_house_direction"
		controller = decision_option_list_controller
		decision_to_second_step_button = "CHOOSE_UNITY_DIRECTION"
		show_from_start = yes

		### Increase Unity
		item = {
			value = steer_unity_towards_harmonious
			is_valid = {
				custom_tooltip = {
					text = steer_unity_towards_harmonious_tt
					NOT = { house = { has_house_unity_stage = harmonious } }
				}
			}
			current_description = steer_unity_towards_harmonious_desc
			localization = steer_unity_towards_harmonious_name
			icon = "gfx/interface/icons/currencies/house_unity/harmonious.dds"
			ai_chance = {
				value = 100
				if = {
					limit = { ai_wants_low_unity = yes }
					multiply = 0
				}
			}
		}
		### Decrease Unity
		item = {
			value = steer_unity_towards_antagonistic
			is_valid = {
				custom_tooltip = {
					text = steer_unity_towards_antagonistic_tt
					NOT = { house = { has_house_unity_stage = antagonistic } }
				}
			}
			current_description = steer_unity_towards_antagonistic_desc
			localization = steer_unity_towards_antagonistic_name
			icon = "gfx/interface/icons/currencies/house_unity/antagonistic.dds"
			ai_chance = {
				value = 100
				if = {
					limit = { ai_wants_high_unity = yes }
					multiply = 0
				}
			}
		}
	}

	effect = {
		if = { # Increase Unity
			limit = { scope:steer_unity_towards_harmonious = yes }
			
			house = {
				add_unity_value = {
					value = massive_unity_gain
					character = root
					desc = clan_unity_steer_direction_change.desc
				}
			}
			custom_tooltip = steer_unity_towards_harmonious_passive_gain_tt
			add_character_flag = {
				flag = steer_unity_towards_harmonious_passive_gain
				years = 10
			}
			
			# Let's send notifications to relevant characters
			hidden_effect = {
				# Send a toast to yourself, as a confirmation that Unity changed
				send_interface_toast = {
					type = msg_house_unity_change_value
					title = steer_unity_towards_harmonious_toast
					desc = steer_unity_towards_harmonious_toast
					left_icon = root
					show_as_tooltip = {
						house = {
							add_unity_value = {
								value = massive_unity_gain
								character = root
								desc = clan_unity_steer_direction_change.desc
							}
						}
					}
				}
				# Send a notification (we don't want a toast here) to any other player within the house
				every_player = {
					limit = {
						exists = house
						house = root.house
						NOT = { this = root }
					}
					send_interface_message = {
						type = msg_house_unity_change_value
						title = steer_unity_notification_title
						desc = steer_unity_towards_harmonious_toast
						left_icon = root
						show_as_tooltip = {
							house = {
								add_unity_value = {
									value = massive_unity_gain
									character = root
									desc = clan_unity_steer_direction_change.desc
								}
							}
						}
					}
				}
			}
		}
		else_if = { # Decrease Unity
			limit = { scope:steer_unity_towards_antagonistic = yes }
			
			house = {
				add_unity_value = {
					value = massive_unity_loss
					character = root
					desc = clan_unity_steer_direction_change.desc
				}
			}
			custom_tooltip = steer_unity_towards_antagonistic_passive_loss_tt
			add_character_flag = {
				flag = steer_unity_towards_antagonistic_passive_loss
				years = 10
			}
			
			# Let's send notifications to relevant characters
			hidden_effect = {
				# Send a toast to yourself, as a confirmation that Unity changed
				send_interface_toast = {
					type = msg_house_unity_change_value
					title = steer_unity_towards_antagonistic_toast
						desc = steer_unity_towards_antagonistic_toast
					left_icon = root
					show_as_tooltip = {
						house = {
							add_unity_value = {
								value = massive_unity_loss
								character = root
								desc = clan_unity_steer_direction_change.desc
							}
						}
					}
				}
				# Send a notification (we don't want a toast here) to any other player within the house
				every_player = {
					limit = {
						exists = house
						house = root.house
						NOT = { this = root }
					}
					send_interface_message = {
						type = msg_house_unity_change_value
						title = steer_unity_notification_title
						desc = steer_unity_towards_antagonistic_toast
						left_icon = root
						show_as_tooltip = {
							house = {
								add_unity_value = {
									value = massive_unity_loss
									character = root
									desc = clan_unity_steer_direction_change.desc
								}
							}
						}
					}
				}
			}
		}
	}
	
	cost = {
		piety = {
			value = unity_major_decision_piety_cost
		}
	}
	
	ai_potential = {
		highest_held_title_tier >= tier_county # Barons doesn't have to use the decision
		is_landed = yes
		exists = house
	}

	ai_will_do = {
		base = 20
		
		# If unity is at max or min levels, increase the AI weight if they want to go in the opposite direction
		modifier = {
			OR = {
				ai_wants_high_unity = yes
				ai_wants_low_unity = yes
			}
			add = 40
		}
		
		# If unity is at max or min levels, increase the AI weight if they want to go in the opposite direction
		modifier = {
			OR = {
				AND = {
					ai_wants_high_unity = yes
					OR = {
						house = { has_house_unity_stage = antagonistic }
						house = { has_house_unity_stage = competitive }
					}
				}
				AND = {
					ai_wants_low_unity = yes
					OR = {
						house = { has_house_unity_stage = harmonious }
						house = { has_house_unity_stage = friendly }
					}
				}
			}
			add = 40
		}
	}
}

# General Unity decisions - These are available to all members of a House
unity_search_for_administrators_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3_decision_tax_collector.dds"
	}
	sort_order = 60
	decision_group_type = house_unity

	desc = unity_search_for_administrators_decision_desc

	cooldown = { years = 10 }

	is_shown = {
		always = no													# Shogunate: disabled
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}

	is_valid = {
	}

	effect = {
		custom_tooltip = search_administors_decision.tt
		hidden_effect = {
			random_list = {
				40 = {
					save_temporary_scope_value_as = {
						name = number_of_new_administrators
						value = 1
					}
				}
				40 = {
					save_temporary_scope_value_as = {
						name = number_of_new_administrators
						value = 2
					}
				}
				20 = {
					save_temporary_scope_value_as = {
						name = number_of_new_administrators
						value = 3
					}
				}
			}
			while = {
				count = scope:number_of_new_administrators
				create_character = {
					template = administrator_character
					employer = root
					faith = root.faith
					culture = root.culture
					gender_female_chance = {
						if = {
							limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
							add = 0
						}
						else_if = {
							limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
							add = 100
						}
						else = {
							add = 50
						}
					}
					save_scope_as = new_administrator
				}
				send_interface_message = {
					type = event_dynasty_good_with_text
					title = unity_search_for_administrators_decision.msg.t
					desc = unity_search_for_administrators_decision.msg.desc
					left_icon = scope:new_administrator
				}
			}
		}
	}
	
	cost = { # We give the AI some handicap here by making the decision free for them, but they only ever use it if they don't have any tax collectors at all
		gold = {
			value = 0
			if = {
				limit = { is_ai = no }
				add = minor_gold_value
			}
		}
		piety = {
			value = 0
			if = {
				limit = { is_ai = no }
				add = medium_piety_value
			}
		}
	}
	
	ai_potential = {
		any_tax_collector = { count <= 0 }
	}

	ai_will_do = {
		base = 100
	}
}

# FP3 Unity Decisions
unity_improve_logistics_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_concession.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_improve_logistics_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		has_fp3_dlc_trigger = yes
		culture = { has_cultural_pillar = heritage_iranian }
		government_has_flag = government_is_clan
		is_landed = yes
		exists = house
	}

	is_valid = {
		# We show the culture requirement here to tell the player why they have the decision available
		culture = { has_cultural_pillar = heritage_iranian }
		house = {
			OR = {
				has_house_unity_stage = antagonistic
				has_house_unity_stage = competitive
			}
		}
		is_house_head = yes
	}

	is_valid_showing_failures_only = {
		house = {
			OR = {
				has_house_unity_stage = antagonistic
				has_house_unity_stage = competitive
			}
			NOT = { has_house_unity_modifier = fp3_unity_improved_logistics_modifier }
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_unity_modifier = {
				modifier = fp3_unity_improved_logistics_modifier
				years = 10
			}
		}
	}

	cost = {
		gold = {
			value = medium_gold_value
		}
		piety = {
			value = unity_major_decision_piety_cost
			add = {
				value = 20
				multiply = {
					value = number_of_landed_house_members_value
					subtract = 1 # We don't want to add any extra for the first ruler
				}
			}
		}
	}
	
	ai_potential = {
		exists = house
		house = { # Don't bother unless you have a few landed house members who would benefit
			any_house_unity_member = {
				count >= 3
			}
		}
		ai_has_warlike_personality = yes
	}

	ai_will_do = {
		base = 10
	}
}

unity_promote_development_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_golden_age.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_promote_development_decision_desc

	cooldown = { years = 20 }

	is_shown = {
		has_fp3_dlc_trigger = yes
		culture = { has_cultural_pillar = heritage_iranian }
		government_has_flag = government_is_clan
		is_landed = yes
		exists = house
	}

	is_valid = {
		# We show the culture requirement here to tell the player why they have the decision available
		culture = { has_cultural_pillar = heritage_iranian }
		house = {
			OR = {
				has_house_unity_stage = friendly
				has_house_unity_stage = harmonious
			}
		}
		is_house_head = yes
	}

	is_valid_showing_failures_only = {
		house = {
			OR = {
				has_house_unity_stage = friendly
				has_house_unity_stage = harmonious
			}
			NOT = { has_house_unity_modifier = fp3_unity_promoted_development_modifier }
		}
		is_house_head = yes
	}

	effect = {
		house = {
			add_house_unity_modifier = {
				modifier = fp3_unity_promoted_development_modifier
				years = 10
			}
		}
	}

	cost = {
		gold = {
			value = medium_gold_value
		}
		piety = {
			value = unity_major_decision_piety_cost
			add = {
				value = 20
				multiply = {
					value = number_of_landed_house_members_value
					subtract = 1 # We don't want to add any extra for the first ruler
				}
			}
		}
	}
	
	ai_potential = {
		exists = house
		house = { # Don't bother unless you have a few landed house members who would benefit
			any_house_unity_member = {
				count >= 3
			}
		}
		ai_has_warlike_personality = no
	}

	ai_will_do = {
		base = 10
	}
}

unity_consult_house_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	is_invisible = yes
	
	sort_order = 60

	desc = unity_consult_house_decision_desc

	is_shown = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		exists = house
	}

	is_valid = {
		house = {
			has_house_unity_stage = impassive
		}
	}
	
	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = unity_consult_house_decision.tt_cooldown
			NOT = { has_character_flag = fp3_consulted_house }
		}
	}

	effect = {
		custom_tooltip = unity_consult_house_decision.tt_house_council_bonus
		#custom_tooltip = unity_consult_house_decision.tt_no_unity_change
		custom_tooltip = unity_consult_house_decision.tt_lifetime
		add_character_flag = {
			flag = fp3_consulted_house
		}
	}
	
	cost = {
		piety = { value = unity_minor_decision_piety_cost }
	}
	
	ai_potential = {
		exists = house
		# AI has more than 1 house member that is their vassal/courtier (can serve as a councillor)
		house = {
			any_house_member = {
				count > 1
				OR = {
					is_vassal_of = root
					is_courtier_of = root
				}
			}
		}
	}

	ai_will_do = {
		base = 20
		# AI has more than 1 house member actively serving as a councillor
		modifier = {
			any_councillor = {
				count > 1
				exists = house
				house = root.house
			}
			add = 100
		}
		# Benefits AI to stack family buffs
		modifier = {
			culture = { has_cultural_parameter = close_family_better_councillors }
			add = 50
		}
	}
}

unity_establish_futuwaa_lodges_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/competitive.dds"
	}
	is_invisible = yes
	sort_order = 60

	desc = {
		desc = unity_establish_futuwaa_lodges_decision_desc_intro
		first_valid = {
			# "People"
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							has_dlc_feature = diverge_culture
							culture = { has_cultural_parameter = martial_custom_equal_combatant } 
						}
						faith = { has_doctrine_parameter = combatant_can_be_either_gender_if_no_roco }
						has_character_modifier = ignores_gender_army_rules
						culture = { 
							OR = {
								has_cultural_parameter = has_access_to_shieldmaidens
								has_cultural_parameter = high_prowess_ignores_knight_restrictions
							}
						}
					}
				}
				desc = people
			}
			# "Women"
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							has_dlc_feature = diverge_culture
							culture = { has_cultural_parameter = martial_custom_female_only_combatant } 
						}
						faith = { has_doctrine_parameter = combatant_must_be_female_if_no_roco }
					}
				}
				desc = women
			}
			# "Men"
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							has_dlc_feature = diverge_culture
							culture = { has_cultural_parameter = martial_custom_male_only_combatant } 
						}
						faith = { has_doctrine_parameter = combatant_must_be_male_if_no_roco }
					}
				}
				desc = loc_men
			}
		}
		desc = unity_establish_futuwaa_lodges_decision_desc_outro
	}

	cooldown = { years = 20 }

	is_shown = {
		government_has_flag = government_is_clan
		is_landed = yes
		exists = house
		exists = capital_province # Sanity check
		# TODO_CD_EREN: Allow this for people w/o the tradition but nerf it (and rename it)
		# Otherwise, put it in the valid as well so the tooltip is surfaced to the player
		culture = { has_cultural_tradition = tradition_futuwaa }
	}

	is_valid = {
		house = {
			OR = {
				has_house_unity_stage = antagonistic
				has_house_unity_stage = competitive
			}
		}
	}

	effect = {
		save_scope_as = sponsor # For loc

		# Yup this nonsense is necessary, custom_tooltip does not support triggered_desc
		if = {
			limit = {
				OR = {
					AND = {
						has_dlc_feature = diverge_culture
						culture = { has_cultural_parameter = martial_custom_equal_combatant } 
					}
					faith = { has_doctrine_parameter = combatant_can_be_either_gender_if_no_roco }
					has_character_modifier = ignores_gender_army_rules
					culture = {
						OR = {
							has_cultural_parameter = has_access_to_shieldmaidens
							has_cultural_parameter = high_prowess_ignores_knight_restrictions
						}
					}
				}
			}
			save_scope_as = any_combatants # This is relevant for a TT later on
			custom_tooltip = { text = unity_establish_futuwaa_lodges_decision.tt_people }
		}
		else_if = {
			limit = {
				OR = {
					AND = {
						has_dlc_feature = diverge_culture
						culture = { has_cultural_parameter = martial_custom_female_only_combatant } 
					}
					faith = { has_doctrine_parameter = combatant_must_be_female_if_no_roco }
				}
			}
			save_scope_as = female_combatants
			custom_tooltip = { text = unity_establish_futuwaa_lodges_decision.tt_women }
		}
		else_if = {
			limit = {
				OR = {
					AND = {
						has_dlc_feature = diverge_culture
						culture = { has_cultural_parameter = martial_custom_male_only_combatant } 
					}
					faith = { has_doctrine_parameter = combatant_must_be_male_if_no_roco }
				}
			}
			save_scope_as = male_combatants
			custom_tooltip = { text = unity_establish_futuwaa_lodges_decision.tt_men }
		}
		

		if = {
			limit = { exists = scope:any_combatants }
			custom_tooltip = { text = unity_establish_futuwaa_lodges_decision.tt_num_people }
		}
		else_if = {
			limit = { exists = scope:female_combatants }
			custom_tooltip = { text = unity_establish_futuwaa_lodges_decision.tt_num_women }
		}
		else_if = {
			limit = { exists = scope:male_combatants }
			custom_tooltip = { text = unity_establish_futuwaa_lodges_decision.tt_num_men }
		}

		add_character_modifier = {
			modifier = fp3_established_futuwaa_lodges_modifier
			years = 20
		}

		add_character_flag = {
			flag = fp3_established_futuwaa_lodges
			years = 20
		}
		
		create_story = story_cycle_futuwaa_lodges
	}

	cost = {
		piety = { value = unity_minor_decision_piety_cost }
	}

	ai_will_do = {
		base = 20
		# Chance increases if root has lots of valid members
		modifier = {
			add = 40
			any_courtier = {
				count >= 2
				fp3_is_valid_futuwaa_member = { SPONSOR = root }
			}
		}
		modifier = {
			add = 40
			any_courtier = {
				count >= 4
				fp3_is_valid_futuwaa_member = { SPONSOR = root }
			}
		}
	}
}

unity_educate_youth_in_madrasas_decision = {
	ai_check_interval = 36
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_secret_faith.dds"
	}
	is_invisible = yes
	sort_order = 60

	title = {
		desc = unity_educate_youth_in_madrasas_decision.t_intro
		first_valid = {
			# Call them madrasas if our capital is advanced enough
			triggered_desc = {
				trigger = {
					capital_county ?= {
						development_level >= bad_development_level
					}
				}
				desc = unity_educate_youth_in_madrasas_decision.t_madrasas
			}
			# Otherwise just say that the youth are being educated in houses of worship
			desc = unity_educate_youth_in_madrasas_decision.t_houses_of_worship
		}
	}

	desc = {
		desc = unity_educate_youth_in_madrasas_decision_desc_intro
		first_valid = {
			# "People"
			triggered_desc = {
				trigger = { has_realm_law = equal_law }
				desc = people
			}
			# "Women"
			triggered_desc = {
				trigger = {
					OR = {
						has_realm_law = female_only_law
						has_realm_law = female_preference_law
					}
				}
				desc = women
			}
			# "Men"
			triggered_desc = {
				trigger = {
					OR = {
						has_realm_law = male_only_law
						has_realm_law = male_preference_law
					}
				}
				desc = loc_men
			}
		}
		desc = unity_educate_youth_in_madrasas_decision_desc_outro
	}

	cooldown = { years = 20 }

	is_shown = {
		government_has_flag = government_is_clan
		is_landed = yes
		exists = house
		exists = capital_province # Sanity check
		culture = { has_cultural_tradition = tradition_fp3_beacon_of_learning } # TODO_CD_EREN: Allow this for people w/o the tradition, but nerf it. See the futuwaa decision
	}

	is_valid = {
		is_at_war = no
		house = {
			OR = {
				has_house_unity_stage = harmonious
				has_house_unity_stage = friendly
			}
		}
	}

	effect = {
		save_scope_as = sponsor # For loc
		# TT for who is educated
		# Yup this nonsense is necessary, custom_tooltip does not support triggered_desc
		if = {
			limit = { has_realm_law = equal_law }
			save_scope_as = realm_law_people # This is relevant for a TT later on
			custom_tooltip = { text = unity_educate_youth_in_madrasas_decision.tt_people }
		}
		else_if = {
			limit = {
				OR = {
					has_realm_law = female_only_law
					has_realm_law = female_preference_law
				}
			}
			save_scope_as = realm_law_women
			custom_tooltip = { text = unity_educate_youth_in_madrasas_decision.tt_women }
		}
		else_if = {
			limit = {
				OR = {
					has_realm_law = male_only_law
					has_realm_law = male_preference_law
				}
			}
			save_scope_as = realm_law_men
			custom_tooltip = { text = unity_educate_youth_in_madrasas_decision.tt_men }
		}

		if = {
			limit = { exists = scope:realm_law_people }
			custom_tooltip = { text = unity_educate_youth_in_madrasas_decision.tt_num_people }
		}
		else_if = {
			limit = { exists = scope:realm_law_women }
			custom_tooltip = { text = unity_educate_youth_in_madrasas_decision.tt_num_women }
		}
		else_if = {
			limit = { exists = scope:realm_law_men }
			custom_tooltip = { text = unity_educate_youth_in_madrasas_decision.tt_num_men }
		}

		add_character_modifier = {
			modifier = fp3_established_madrasas_modifier
			years = 20
		}

		add_character_flag = {
			flag = fp3_educated_youth_in_madrasas
			years = 20
		}
		
		create_story = story_cycle_madrasas
	}
	
	cost = {
		piety = { value = unity_minor_decision_piety_cost }
	}
	
	ai_potential = {
		exists = house
		# AI has at least one valid madrasa pupil
		any_courtier = {
			# Young
			fp3_is_valid_madrasa_pupil = { SPONSOR = root }
		}
	}

	ai_will_do = {
		base = 20
		# Chance increases if root has lots of valid members
		modifier = {
			add = 40
			any_courtier = {
				count >= 2
				fp3_is_valid_madrasa_pupil = { SPONSOR = root }
			}
		}
		modifier = {
			add = 40
			any_courtier = {
				count >= 4
				fp3_is_valid_madrasa_pupil = { SPONSOR = root }
			}
		}
	}
}
